package com.yidu.qianfeng.service.impl;

import com.yidu.qianfeng.common.bean.finance.Finance;
import com.yidu.qianfeng.common.bean.finance.FinanceCondition;
import com.yidu.qianfeng.common.bean.finance.Income;
import com.yidu.qianfeng.common.util.JsonMsgUtil;
import com.yidu.qianfeng.common.util.LayuiJsonWrap;
import com.yidu.qianfeng.mapper.FinanceMapper;
import com.yidu.qianfeng.mapper.IncomeMapper;
import com.yidu.qianfeng.service.FinanceServiceInter;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service("financeServiceImpl")
public class FinanceServiceImpl implements FinanceServiceInter {
    @Resource(name = "financeMapper")
    private FinanceMapper financeMapper;

    @Override
    public String insertFinance(Finance finance) {
        int insert = financeMapper.insert(finance);
        String jsonMessage = JsonMsgUtil.createJsonMessage(insert, "新增成功", "新增失败");
        return jsonMessage;
    }

    @Override
    public List<Finance> selectAllFinance(int page, int limit) {
        return financeMapper.selectAllFinance(page,limit);
    }

    @Override
    public int selectFinanceCount() {
        return financeMapper.selectFinanceCount();
    }

    @Override
    public LayuiJsonWrap selectFinanceByCondition(FinanceCondition condition) {
        condition.setOffset((condition.getPage()-1)*condition.getCount());
        condition.setFinanceVoucherNum("%"+condition.getFinanceVoucherNum()+"%");
        return new LayuiJsonWrap(condition.getCount(),financeMapper.selectFinanceByCondition(condition));
    }

    @Override
    public String updatePersonal(String[] ids) {
        String jsonMessage = null;
        for (String id : ids) {
            int i = financeMapper.updatePersonal(id);
                jsonMessage = JsonMsgUtil.createJsonMessage(i, "审核成功", "已审核");
        }
        return jsonMessage;
    }

    @Override
    public String updateSubstation(String[] ids) {
        String jsonMessage = null;
        for (String id : ids) {
            int i = financeMapper.updateSubstation(id);
            jsonMessage = JsonMsgUtil.createJsonMessage(i, "审核成功", "已审核");
        }
        return jsonMessage;
    }
}
